const { Service } = require('egg')

class PlanService extends Service{
    /**
     * 查询计划报告列表
     */
    async index(payload){
        const { ctx } = this;
        let { name = "" } = payload;
        const { Op } = this.ctx.model.Sequelize
        return await ctx.model.Plan.findAll({
            where: {
                name: {
                    [Op.like]: '%' + name + '%'
                }
            },
            order: [['sortValue', 'DESC']]
        })
    }

    /**
     * 计划报告修改
     */
    async update(payload){
        return await this.ctx.model.Plan.update(payload, {
            where: {
                id: payload.id
            }
        })
    }

    /**
     * 计划报告添加
     */
    async create(payload){
        return await this.ctx.model.Plan.create(payload)
    }

    /**
     * 计划报告删除
     */
    async delete(payload){
        return await this.ctx.model.Plan.destroy({
            where: {
                id: payload.id
            }
        })
    }


}


module.exports = PlanService